<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>File: util.rb</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



  <div id="fileHeader">
    <h1>util.rb</h1>
    <table class="header-table">
    <tr class="top-aligned-row">
      <td><strong>Path:</strong></td>
      <td>lib/svengali/util.rb
      </td>
    </tr>
    <tr class="top-aligned-row">
      <td><strong>Last Update:</strong></td>
      <td>Sun Jul 11 10:55:34 +0900 2010</td>
    </tr>
    </table>
  </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">


    <div id="requires-list">
      <h3 class="section-bar">Required files</h3>

      <div class="name-list">
      socket&nbsp;&nbsp;
      </div>
    </div>

   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000007">change_platform</a>&nbsp;&nbsp;
      <a href="#M000009">check_has_keys</a>&nbsp;&nbsp;
      <a href="#M000002">debug_p</a>&nbsp;&nbsp;
      <a href="#M000008">err_message_and_exit</a>&nbsp;&nbsp;
      <a href="#M000011">find_machines_on_range_by_ping</a>&nbsp;&nbsp;
      <a href="#M000010">is_exist_by_ping</a>&nbsp;&nbsp;
      <a href="#M000004">lazy_inp</a>&nbsp;&nbsp;
      <a href="#M000006">load_plugin</a>&nbsp;&nbsp;
      <a href="#M000003">not_inp</a>&nbsp;&nbsp;
      <a href="#M000005">not_tested</a>&nbsp;&nbsp;
      <a href="#M000001">stop_debug_print</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000007" class="method-detail">
        <a name="M000007"></a>

        <div class="method-heading">
          <a href="#M000007" class="method-signature">
          <span class="method-name">change_platform</span><span class="method-args">(platform_name_str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
change platform &quot;default&quot; to <b>platform_name_str</b>
&quot;default&quot; was specified on svengali.rb on ahead
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000007-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 64</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">change_platform</span>(<span class="ruby-identifier">platform_name_str</span>)
  <span class="ruby-identifier">require</span> <span class="ruby-node">&quot;#{LIBNAME}/platforms/&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">platform_name_str</span>
  <span class="ruby-identifier">$platform_name</span> = <span class="ruby-identifier">platform_name_str</span>
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="#M000009" class="method-signature">
          <span class="method-name">check_has_keys</span><span class="method-args">(params_hash,array_of_symbols)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
*<b>Attention</b>* this method passes nil values
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000009-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 77</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">check_has_keys</span>(<span class="ruby-identifier">params_hash</span>,<span class="ruby-identifier">array_of_symbols</span>)
  <span class="ruby-identifier">array_of_symbols</span>.<span class="ruby-identifier">each</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">symbol</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">params_hash</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">symbol</span>)
      <span class="ruby-identifier">err_message_and_exit</span>(<span class="ruby-value str">&quot;please specify a value of :&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">symbol</span>.<span class="ruby-identifier">to_s</span>() <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;!&quot;</span>)
    <span class="ruby-keyword kw">end</span>
  }
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000002" class="method-detail">
        <a name="M000002"></a>

        <div class="method-heading">
          <a href="#M000002" class="method-signature">
          <span class="method-name">debug_p</span><span class="method-args">(str = &quot;&quot;)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000002-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 35</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">debug_p</span>(<span class="ruby-identifier">str</span> = <span class="ruby-value str">&quot;&quot;</span>)
  <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$output_debug_print</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;[DEBUG #{caller(1)[0]}] #{str}&quot;</span>
  <span class="ruby-keyword kw">end</span>
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000008" class="method-detail">
        <a name="M000008"></a>

        <div class="method-heading">
          <a href="#M000008" class="method-signature">
          <span class="method-name">err_message_and_exit</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000008-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 69</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">err_message_and_exit</span>(<span class="ruby-identifier">str</span>)
  <span class="ruby-identifier">debug_p</span> <span class="ruby-identifier">str</span>
  <span class="ruby-identifier">debug_p</span> <span class="ruby-value str">&quot;I'm exiting!&quot;</span>

  <span class="ruby-identifier">exit</span>()
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">find_machines_on_range_by_ping</span><span class="method-args">(ipaddr_range_str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
ipaddr_range_str is like below
</p>
<pre>
           &quot;192.168.1.100-200&quot;
</pre>
<p>
return -&gt; hash : { string of ipaddr =&gt; true, .&#8230;.&#8230; ,
string of ipaddr =&gt; true}
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 100</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_machines_on_range_by_ping</span>(<span class="ruby-identifier">ipaddr_range_str</span>)
  <span class="ruby-identifier">octets_arr</span> = <span class="ruby-identifier">ipaddr_range_str</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;.&quot;</span>)
  <span class="ruby-identifier">splited_last_octet</span> = <span class="ruby-identifier">octets_arr</span>[<span class="ruby-value">3</span>].<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;-&quot;</span>)

  <span class="ruby-identifier">alive_hash</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>()
  <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">last_octet</span> <span class="ruby-keyword kw">in</span> <span class="ruby-identifier">splited_last_octet</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">..</span> <span class="ruby-identifier">splited_last_octet</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>
    <span class="ruby-identifier">t</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
      <span class="ruby-identifier">dest_ip_str</span> = <span class="ruby-identifier">octets_arr</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;.&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">octets_arr</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;.&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">octets_arr</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;.&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">last_octet</span>.<span class="ruby-identifier">to_s</span>()
      <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">is_exist_by_ping</span>(<span class="ruby-constant">CLibIPAddr</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">dest_ip_str</span>))
        <span class="ruby-identifier">alive_hash</span>[<span class="ruby-identifier">dest_ip_str</span>] = <span class="ruby-keyword kw">true</span>
      <span class="ruby-keyword kw">end</span>
    <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">end</span>

  <span class="ruby-identifier">t</span>.<span class="ruby-identifier">join</span>

  <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">alive_hash</span>
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000010" class="method-detail">
        <a name="M000010"></a>

        <div class="method-heading">
          <a href="#M000010" class="method-signature">
          <span class="method-name">is_exist_by_ping</span><span class="method-args">(ipaddr)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
ipaddr -&gt; ClibIPAddr : destination IP address return -&gt; boolean
</p>
<p>
This method returns at most 3sec after
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000010-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 89</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_exist_by_ping</span>(<span class="ruby-identifier">ipaddr</span>)
  <span class="ruby-comment cmt"># this execution returns at most 3sec after</span>
  <span class="ruby-node">`ping #{ipaddr.to_s} -c 1 -w 3`</span>
  <span class="ruby-identifier">result</span> = ( <span class="ruby-identifier">$?</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> ) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span>
  <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000004" class="method-detail">
        <a name="M000004"></a>

        <div class="method-heading">
          <a href="#M000004" class="method-signature">
          <span class="method-name">lazy_inp</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000004-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 45</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lazy_inp</span>()
  <span class="ruby-identifier">debug_p</span>(<span class="ruby-identifier">caller</span>(<span class="ruby-value">1</span>)[<span class="ruby-value">0</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot; -&gt; Lazily implemented. Here should be fixed if you have time.&quot;</span>)
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000006" class="method-detail">
        <a name="M000006"></a>

        <div class="method-heading">
          <a href="#M000006" class="method-signature">
          <span class="method-name">load_plugin</span><span class="method-args">(plugin_name_str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000006-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 53</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_plugin</span>(<span class="ruby-identifier">plugin_name_str</span>)
  <span class="ruby-comment cmt">#    open( File::dirname(__FILE__) + &quot;/plugin/&quot; + plugin_name_str + &quot;.rb&quot;){ |file|</span>
  <span class="ruby-comment cmt">#      contents = file.read()</span>
  <span class="ruby-comment cmt">#      contents = &quot;class Machine\n&quot; + contents + &quot;\nend&quot;</span>
  <span class="ruby-comment cmt">#      eval(contents)</span>
  <span class="ruby-comment cmt">#    }</span>
  <span class="ruby-identifier">require</span> <span class="ruby-node">&quot;#{LIBNAME}/plugins/&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">plugin_name_str</span>
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000003" class="method-detail">
        <a name="M000003"></a>

        <div class="method-heading">
          <a href="#M000003" class="method-signature">
          <span class="method-name">not_inp</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000003-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 41</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">not_inp</span>()
  <span class="ruby-identifier">debug_p</span>(<span class="ruby-identifier">caller</span>(<span class="ruby-value">1</span>)[<span class="ruby-value">0</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot; -&gt; Not implemented yet.&quot;</span>)
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="#M000005" class="method-signature">
          <span class="method-name">not_tested</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000005-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 49</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">not_tested</span>()
  <span class="ruby-identifier">debug_p</span>(<span class="ruby-identifier">caller</span>(<span class="ruby-value">1</span>)[<span class="ruby-value">0</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot; -&gt; Not tested yet.&quot;</span>)
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000001" class="method-detail">
        <a name="M000001"></a>

        <div class="method-heading">
          <a href="#M000001" class="method-signature">
          <span class="method-name">stop_debug_print</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000001-source">
<pre>
<span class="ruby-comment cmt"># File lib/svengali/util.rb, line 31</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop_debug_print</span>()
  <span class="ruby-identifier">$output_debug_print</span> = <span class="ruby-keyword kw">false</span>
<span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>